package com.zj.study.pojo.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zj.study.entity.User;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author 赵赳
 * @since 2021/10/21 11:27
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class UserQuery {

  //private final static Long PAGE_NO = 0L;
  //
  //private final static Long PAGE_SIZE = 10L;

  private Long id;

  private String name;

  //private Long pageNo = PAGE_NO;
  //
  //private Long pageSize = PAGE_SIZE;

  private Integer age;

  private String email;

  //public Page<User> toPage() {
  //  return new Page<>(pageNo, pageSize);
  //}

  public LambdaQueryWrapper<User> toQuery() {
    return new LambdaQueryWrapper<User>()
        .eq(Objects.nonNull(id), User::getId, id)
        .like(Objects.nonNull(name), User::getName, name)
        .eq(Objects.nonNull(age), User::getAge, age)
        .like(Objects.nonNull(email), User::getEmail, email);
  }

}
